home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / GDebi / GDebiCli.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  4.6 KB  |  140 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import time
  6. import thread
  7. import os
  8. import fcntl
  9. import string
  10. import warnings
  11. from warnings import warn
  12. warnings.filterwarnings('ignore', 'apt API not stable yet', FutureWarning)
  13. import apt
  14. import apt_pkg
  15. from gettext import gettext as _
  16. from DebPackage import DebPackage, Cache
  17. from DscSrcPackage import DscSrcPackage
  18. from subprocess import PIPE, Popen, call
  19.  
  20. class GDebiCli(object):
  21.     
  22.     def __init__(self, options):
  23.         self.options = options
  24.         if options.quiet:
  25.             tp = apt.progress.OpProgress()
  26.         else:
  27.             tp = apt.progress.OpTextProgress()
  28.         if options.rootdir and os.path.exists(options.rootdir + '/usr/bin/dpkg'):
  29.             arch = Popen([
  30.                 options.rootdir + '/usr/bin/dpkg',
  31.                 '--print-architecture'], stdout = PIPE).communicate()[0]
  32.             if arch:
  33.                 apt_pkg.Config.Set('APT::Architecture', arch.strip())
  34.             
  35.         
  36.         if options.apt_opts:
  37.             for o in options.apt_opts:
  38.                 if o.find('=') < 0:
  39.                     sys.stderr.write(_('Configuration items must be specified with a =<value>\n'))
  40.                     sys.exit(1)
  41.                 
  42.                 (name, value) = o.split('=', 1)
  43.                 
  44.                 try:
  45.                     apt_pkg.Config.Set(name, value)
  46.                 continue
  47.                 sys.stderr.write(_("Couldn't set APT option %s to %s\n") % (name, value))
  48.                 sys.exit(1)
  49.                 continue
  50.  
  51.             
  52.         
  53.         self._cache = Cache(tp, rootdir = options.rootdir)
  54.  
  55.     
  56.     def open(self, file):
  57.         
  58.         try:
  59.             if file.endswith('.deb'):
  60.                 self._deb = DebPackage(self._cache, file)
  61.             elif file.endswith('.dsc') or os.path.basename(file) == 'control':
  62.                 self._deb = DscSrcPackage(self._cache, file)
  63.             else:
  64.                 sys.stderr.write(_("Unknown package type '%s', exiting\n") % file)
  65.                 sys.exit(1)
  66.         except (IOError, SystemError):
  67.             e = None
  68.             sys.stderr.write(_('Failed to open the software package\n'))
  69.             sys.stderr.write(_('The package might be corrupted or you are not allowed to open the file. Check the permissions of the file.\n'))
  70.             sys.exit(1)
  71.  
  72.         if not self._deb.checkDeb():
  73.             sys.stderr.write(_('This package is uninstallable\n'))
  74.             sys.stderr.write(self._deb._failureString + '\n')
  75.             return False
  76.         return True
  77.  
  78.     
  79.     def show_description(self):
  80.         
  81.         try:
  82.             print self._deb['Description']
  83.         except KeyError:
  84.             print _('No description is available')
  85.  
  86.  
  87.     
  88.     def show_dependencies(self):
  89.         (install, remove, unauthenticated) = self._deb.requiredChanges
  90.         if len(unauthenticated) > 0:
  91.             print _('The following packages are UNAUTHENTICATED: ')
  92.             for pkgname in unauthenticated:
  93.                 print pkgname + ' ',
  94.             
  95.         
  96.         if len(remove) > 0:
  97.             print _('Requires the REMOVAL of the following packages: ')
  98.             for pkgname in remove:
  99.                 print pkgname + ' ',
  100.             
  101.         
  102.         print 
  103.         if len(install) > 0:
  104.             print _('Requires the installation of the following packages: ')
  105.             for pkgname in install:
  106.                 print pkgname + ' ',
  107.             
  108.         
  109.         print 
  110.  
  111.     
  112.     def install(self):
  113.         (install, remove, unauthenticated) = self._deb.requiredChanges
  114.         if len(install) > 0 or len(remove) > 0:
  115.             fprogress = apt.progress.TextFetchProgress()
  116.             iprogress = apt.progress.InstallProgress()
  117.             res = self._cache.commit(fprogress, iprogress)
  118.         
  119.         if self._deb.file.endswith('.dsc'):
  120.             pass
  121.         else:
  122.             ret = call([
  123.                 'dpkg',
  124.                 '-i',
  125.                 self._deb.file])
  126.  
  127.  
  128. if __name__ == '__main__':
  129.     app = GDebiCli()
  130.     if not app.open(sys.argv[1]):
  131.         sys.exit(1)
  132.     
  133.     print _('Do you want to install the software package? [y/N]:'),
  134.     sys.stdout.flush()
  135.     res = sys.stdin.readline()
  136.     if res.startswith('y') or res.startswith('Y'):
  137.         app.install()
  138.     
  139.  
  140.